package top.lishuoboy.druid;

import cn.hutool.db.DbUtil;
import cn.hutool.db.Entity;
import cn.hutool.setting.dialect.Props;
import cn.hutool.setting.dialect.PropsUtil;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.List;

/**
 * Druid演示
 */
public class CreateDataSource {
    public static void main(String[] args) throws Exception {
        //1.加载配置文件
        Props props = PropsUtil.get("druid.properties");
        //2.获取连接池对象
        DataSource ds = DruidDataSourceFactory.createDataSource(props);
        //3.获取连接
        Connection conn = ds.getConnection();
        //4.可以使用
        List<Entity> entityList = DbUtil.use(ds).query("select * from user");
        entityList.forEach(entity -> System.err.println(entity));
    }
}